#!/usr/bin/python3
# -*- coding: utf-8 -*-

"""
pyu40 PyQt5 tutorial 

In this example, we reimplement an 
event handler. 

author: Jan Bodnar
website: py40.com 
last edited: January 2015
"""

import sys
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QWidget, QApplication, QLabel


class Example(QWidget):
    
    def __init__(self):
        super().__init__()
        
        self.initUI()
        
        
    def initUI(self):      

        lbl1 = QLabel('Press ESC to exit', self)
        lbl1.move(200, 100)

        self.setGeometry(300, 300, 500, 300)
        self.setWindowTitle('key press event')
        self.show()
        
        
    def keyPressEvent(self, e):
        #键值映射表
        #https://blog.csdn.net/foreverhuylee/article/details/46756243
        if e.key() == Qt.Key_Escape:
            self.close()
        
        
if __name__ == '__main__':
    
    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())

